package com.jiangjiang.eshop.common.json;

import java.util.Objects;

/**
 * @Author Jianghaowen
 * @Date 2021/9/23
 * @Description: 叶子表达式
 * @Version V1.0
 **/

public class LeafJsonExpression implements JsonExpression {
    /**
     * json节点名称
     */
    private String jsonNodeName;

    public LeafJsonExpression(String jsonNodeName) {
        this.jsonNodeName = jsonNodeName;
    }

    @Override
    public Object interpret(JsonExpressionContext context) {

        if(Objects.isNull(context.getCurrentJsonNode())){
            return context.getTargetJson().get(jsonNodeName);
        }
        return context.getCurrentJsonNode().get(jsonNodeName);
    }
}
